package com.dl.redis.controller;

import com.dl.redis.entity.User;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author DL
 * @create 2023-09-11 15:43
 */
@RestController
@RequestMapping("/retry")
public class RetryController {

    @RequestMapping("/test")
    @Retryable(value = Exception.class,maxAttempts = 3,backoff = @Backoff(delay = 1000,multiplier = 1.5))
    public String test(@RequestParam String name){
        return name;
    }

    @RequestMapping("/user")
    @Retryable(value = Exception.class,maxAttempts = 3,backoff = @Backoff(delay = 1000,multiplier = 1.5))
    public User user(@Validated User user){
        return user;
    }

    @Recover
    public String recover(){
        return "recover";
    }

}
